<?php
//  ------------------------------------------------------------------------ //
//                         BOOX - MODULE FOR XOOPS 2                         //
//                  Copyright (c) 2005-2006 Instant Zero                     //
//                     <http://xoops.instant-zero.com/>                      //
// ------------------------------------------------------------------------- //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //
class boox_storage
{
	var $files;		// Holds files
	var $filename;	// Name of the file wich contains all the other files

	function boox_storage()
	{
		$this->filename = XOOPS_UPLOAD_PATH.'/boox_files.php';
	}

	/**
 	* Get all the files
 	*/
	function getAllFiles()
	{
		$ret = $tbl_files_list = array();
		$myts =& MyTextSanitizer::getInstance();
		if(file_exists($this->filename)) {
			include_once $this->filename;
			foreach($tbl_files_list as $onefile) {
				if(xoops_trim($onefile)!='') {
					$onefile=$myts->htmlSpecialChars($onefile);
					$ret[$onefile]=$onefile;
				}
			}
		}
		asort($ret);
		$this->files=$ret;
		return $ret;
	}

	/**
 	* Remove one or many files from the list
 	*/
	function delete($file)
	{
		if(is_array($file)) {
			foreach($file as $onefile) {
				if(isset($this->files[$onefile])) {
					unset($this->files[$onefile]);
				}
			}
		} else {
			if(isset($this->files[$file])) {
				unset($this->files[$file]);
			}
		}
	}

	/**
 	* Add one or many Files
 	*/
	function addfiles($file)
	{
		$myts =& MyTextSanitizer::getInstance();
		if(is_array($file)) {
			foreach($file as $onefile) {
				$onefile=xoops_trim($myts->htmlSpecialChars($onefile));
				$this->files[$onefile]=$onefile;
			}
		} else {
			$file=xoops_trim($myts->htmlSpecialChars($file));
			$this->files[$file]=$file;
		}

	}


	/**
 	* Save files
 	*/
	function store()
	{
		if(file_exists($this->filename)) {
			unlink($this->filename);
		}
		$fd = fopen($this->filename,'w') or die('Error unable to create storage files list');
		fputs($fd,"<?php\n");
		fputs($fd,'$tbl_files_list = array('."\n");
		foreach($this->files as $onefile) {
			fputs($fd,"\"".$onefile."\",\n");
		}
		fputs($fd,"'');\n");
		fputs($fd,"?>\n");
		fclose($fd);
	}
}
?>